<?php
$a_tablecolumns_namhoa_user_score_log = array(
    'name'    => 'user_score_log',
    'columns' => array(
        'user_score_log_id' ,
        'userid'            ,
        'type'              ,
        'scoretype'         ,
        'score'             ,
        'data'              ,
        'date'              ,
        'note'              ,
        'updaterid'         ,
        'updatedate'        ,
    ),
);

function get_columns_namhoa_user_score_log() {
    return array(
        'name'    => 'user_score_log',
        'columns' => array(
            'user_score_log_id' ,
            'userid'            ,
            'type'              ,
            'scoretype'         ,
            'score'             ,
            'data'              ,
            'date'              ,
            'note'              ,
            'updaterid'         ,
            'updatedate'        ,
        ),
    );
}

$f_user_score_log_id = 0 ;
$f_userid            = '';
$f_type              = '';
$f_scoretype         = '';
$f_score             = '';
$f_data              = '';
$f_date              = '';
$f_note              = '';
$f_creatorid         = '';
$f_updaterid         = '';
$f_insertdate        = date('Y-m-d H:i:s');
$f_updatedate        = $f_insertdate;

class namhoa_user_score_log {
    public function __get($v_property) {
        return '';
    }
} 

$d_user_score_log = new namhoa_user_score_log();

if (isset($_REQUEST['user_score_log_id' ] )) { $f_user_score_log_id = $_REQUEST['user_score_log_id' ] ; }
if (isset($_REQUEST['userid'            ] )) { $f_userid            = $_REQUEST['userid'            ] ; }
if (isset($_REQUEST['type'              ] )) { $f_type              = $_REQUEST['type'              ] ; }
if (isset($_REQUEST['scoretype'         ] )) { $f_scoretype         = $_REQUEST['scoretype'         ] ; }
if (isset($_REQUEST['score'             ] )) { $f_score             = $_REQUEST['score'             ] ; }
if (isset($_REQUEST['data'              ] )) { $f_data              = $_REQUEST['data'              ] ; }
if (isset($_REQUEST['date'              ] )) { $f_date              = $_REQUEST['date'              ] ; }
if (isset($_REQUEST['note'              ] )) { $f_note              = $_REQUEST['note'              ] ; }

function make_filter_namhoa_user_score_log($s_field, $s_keyword) {
    $v_filter = '';

    if ($s_field != '' && $s_keyword != '') {
        switch ($s_field) {
            case 'userid'            :
            case 'type'              :
            case 'scoretype'         :
            case 'score'             :
            case 'data'              :
            case 'note'              :
            case 'updaterid'         :
            case 'user_score_log_id' :
                $v_filter = "`$s_field` like '%$s_keyword%'";

                break;

            case 'updatedate'        :
                $v_thisday = $v_nextday = date('Y-m-d');

                if (strpos($s_keyword, '~') !== FALSE) {
                    $v_keywords = explode('~', $s_keyword)   ;
                    $v_thisday  = format_date($v_keywords[0]);
                    $v_nextday  = format_date($v_keywords[1]);
                }

                $v_filter = "(`$s_field` >= '$v_thisday 00:00:00' and `$s_field` <= '$v_nextday 23:59:59')";

                break;

            case 'date'              :
                $v_thisday = $v_nextday = date('Y-m-d');

                if (strpos($s_keyword, '~') !== FALSE) {
                    $v_keywords = explode('~', $s_keyword)   ;
                    $v_thisday  = format_date($v_keywords[0]);
                    $v_nextday  = format_date($v_keywords[1]);
                }

                $v_filter = "(`$s_field` >= '$v_thisday' and `$s_field` <= '$v_nextday')";

                break;

        }
    }

    return $v_filter;
}

function make_advanced_filter_namhoa_user_score_log($s_field, $s_keyword) {
    $v_filter = '';

    if ($s_field != '' && $s_keyword != '') {
        switch ($s_field) {
            case 'userid'            :
            case 'type'              :
            case 'scoretype'         :
            case 'score'             :
            case 'data'              :
            case 'note'              :
            case 'updaterid'         :
                $v_filter = "`$s_field` like '%$s_keyword%'";

                break;

            case 'user_score_log_id' :
                if (strpos($s_keyword, '~') !== FALSE) {
                    list($v_from, $v_to) = explode('~', $s_keyword, 2);
                
                    if (is_numeric($v_from)) {
                        $v_filter = $v_filter . "`$s_field` >= $v_from";
                    }
                
                    if (is_numeric($v_to)) {
                        $v_filter = $v_filter . (empty($v_filter) ? '' : ' and ') . "`$s_field` <= $v_to";
                    }
                
                    $v_filter = empty($v_filter) ? '' : "($v_filter)";
                }
                elseif (is_numeric($s_keyword)) {
                    $v_filter = "`$s_field` = $s_keyword";
                }

                break;

            case 'updatedate'        :
                if (strpos($s_keyword, '~') !== FALSE) {
                    list($v_fromday, $v_today) = explode('~', $s_keyword, 2);
                
                    if (validate_date($v_fromday)) {
                        $v_filter = $v_filter . "`$s_field` >= '$v_fromday 00:00:00'";
                    }
                
                    if (validate_date($v_today)) {
                        $v_filter = $v_filter . (empty($v_filter) ? '' : ' and ') . "`$s_field` <= '$v_today 23:59:59'";
                    }
                
                    $v_filter = empty($v_filter) ? '' : "($v_filter)";
                }
                elseif (validate_date($s_keyword)) {
                    $v_filter = "(`$s_field` >= '$s_keyword 00:00:00' and `$s_field` <= '$s_keyword 23:59:59')";
                }

                break;

            case 'date'              :
                if (strpos($s_keyword, '~') !== FALSE) {
                    list($v_fromday, $v_today) = explode('~', $s_keyword, 2);
                
                    if (validate_date($v_fromday)) {
                        $v_filter = $v_filter . "$s_field >= '$v_fromday'";
                    }
                
                    if (validate_date($v_today)) {
                        $v_filter = $v_filter . (empty($v_filter) ? '' : ' and ') . "$s_field <= '$v_today'";
                    }
                
                    $v_filter = empty($v_filter) ? '' : "($v_filter)";
                }
                elseif (validate_date($s_keyword)) {
                    $v_filter = "$s_field = '$s_keyword'";
                }

                break;

        }
    }

    return $v_filter;
}

function build_filter_namhoa_user_score_log($s_field) {
    echo '<option value="user_score_log_id"' , ($s_field == 'user_score_log_id'  ? ' selected="selected"' : ''), '> user_score_log_id </option>';
    echo '<option value="userid"'            , ($s_field == 'userid'             ? ' selected="selected"' : ''), '> Mã Số             </option>';
    echo '<option value="type"'              , ($s_field == 'type'               ? ' selected="selected"' : ''), '> Loại              </option>';
    echo '<option value="scoretype"'         , ($s_field == 'scoretype'          ? ' selected="selected"' : ''), '> Loại Điểm         </option>';
    echo '<option value="score"'             , ($s_field == 'score'              ? ' selected="selected"' : ''), '> Giá Trị           </option>';
    echo '<option value="data"'              , ($s_field == 'data'               ? ' selected="selected"' : ''), '> Dữ Liệu           </option>';
    echo '<option value="date"'              , ($s_field == 'date'               ? ' selected="selected"' : ''), '> Ngày Nhập         </option>';
    echo '<option value="note"'              , ($s_field == 'note'               ? ' selected="selected"' : ''), '> Ghi Chú           </option>';
    echo '<option value="updaterid"'         , ($s_field == 'updaterid'          ? ' selected="selected"' : ''), '> Người Cập Nhật    </option>';
    echo '<option value="updatedate"'        , ($s_field == 'updatedate'         ? ' selected="selected"' : ''), '> Ngày Cập Nhật     </option>';
}

function build_advanced_filter_namhoa_user_score_log($s_field, $a_hide = array()) {
    if (empty($a_hide)) {
        return build_filter_namhoa_user_score_log($s_field);
    }

    $a_columns = array(
        'user_score_log_id' => 'user_score_log_id' ,
        'userid'            => 'Mã Số'             ,
        'type'              => 'Loại'              ,
        'scoretype'         => 'Loại Điểm'         ,
        'score'             => 'Giá Trị'           ,
        'data'              => 'Dữ Liệu'           ,
        'date'              => 'Ngày Nhập'         ,
        'note'              => 'Ghi Chú'           ,
        'updaterid'         => 'Người Cập Nhật'    ,
        'updatedate'        => 'Ngày Cập Nhật'     ,
    );

    $a_hide    = array_combine($a_hide, $a_hide);
    $a_columns = array_diff_key($a_columns, $a_hide);

    foreach ($a_columns as $v_columnname => $v_columncomment) {
        echo '<option value="', $v_columnname, '"', ($s_field == $v_columnname ? ' selected="selected"' : ''), '>', $v_columncomment, '</option>';
    }
}
?>